package com.snowwolf.user.rest;

import com.snowwolf.baseUtil.base.RestResponse;
import com.snowwolf.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: topsnowwolf
 * @description:
 * @date: Create in 2019/3/3 22:33
 * @modified by:
 * @versions：0.1.0
 */
@RestController
public class RestUserController {
    private static Logger logger = LoggerFactory.getLogger(RestUserController.class);
    @Autowired
    private LoadBalancerClient loadBalancerClient;
    @Autowired
    private IUserService userService;
    @RequestMapping("/get")
    public RestResponse getUser(Long id){
        ServiceInstance serviceInstance = this.loadBalancerClient.choose("userApi");
        logger.info("serviceId is ={}, host is = {}, port is ={}",
                serviceInstance.getServiceId(),serviceInstance.getHost(),serviceInstance.getPort());
        return new RestResponse(userService.findOne(id));
    }
}
